<?php  if (!defined('BASEPATH')) exit('No direct script access allowed');

class CI_Transaction_entity{
	var $id = 0;
	var $user_id = 0;
	var $package_id = 0;
	var $type = "";
	var $crDate = 0;
	
	function __destruct() {}
	function __construct() {}
    
	function init($cmd, $input)
	{
		$ci=& get_instance();
		
		if($cmd == 'id')
		{
			$result = $ci->db->where('id',$input)->get(TBL_TRANSACTION)->result();
		}
		else
		{
			return false;
		}
		
		if( !empty($result) )
		{
			$this->id = $result[0]->id;
			$this->user_id = $result[0]->user_id;
			$this->package_id = $result[0]->package_id;
			$this->type = $result[0]->type;
			$this->crDate = $result[0]->crDate;
			
			return $this;
		}
		return false;
	}
	
	function setUserId($input){ $this->user_id=$input; }
	function setPackageId($input){ $this->package_id=$input; }
	function setType($input){ $this->type=$input; }
	function setCrDate($input){ $this->crDate=$input; }
	
	function getId(){ return $this->id; }
	function getUserId(){ return $this->user_id; }
	function getPackageId(){ return $this->package_id; }
	function getType(){ return $this->type; }
	function getCrDate(){ return $this->crDate; } 
	
	function update()
	{
		$ci=& get_instance();
		 
		$ci->db->set('user_id', $this->user_id);
		$ci->db->set('package_id', $this->package_id);
		$ci->db->set('type', $this->type);
		$ci->db->set('crDate', $this->crDate);
		
		$ci->db->where('id', $this->id)->update(TBL_TRANSACTION);
	}
	
	function createNewEntity(){
		$ci=& get_instance();
		
		$ci->db->set('crDate',time() );
		$ci->db->insert(TBL_TRANSACTION);
		
		return $ci->db->insert_id();
	}
	
	function getArrayListOfTransaction($user_id){
		$ci=& get_instance();
		return $ci->db->where("user_id", $user_id)->order_by("crDate", "DESC")->get(TBL_TRANSACTION)->result();
	}
	 
// end class	 
}
